﻿#include <iostream>
#include <functional>
#include <thread>
#include <future>
#include "threadpool.h"
#include <chrono>
#include <random>
using namespace std;


int sum1(int a, int b)
{
    uniform_int_distribution<int> dst(1, 10);
    random_device e;
    std::this_thread::sleep_for(std::chrono::seconds(2));
    //std::this_thread::sleep_for(std::chrono::seconds(dst(e)));
    return a + b;
}   

int main()
{
    //packaged_task<int(int, int)> task(std::bind(sum1, 1, 2));
    //future<int> res = task.get_future();
    //task(1, 2);
    //cout << res.get();

    ThreadPool pool;
    //pool.setMode(PoolMode::MODE_CACHED);
    pool.start(2);

    future<int> res = pool.submitTask(sum1, 1, 2);
    future<int> res1 = pool.submitTask(sum1, 1, 2);
    //future<int> res2 = pool.submitTask(sum1, 1, 2);
    //future<int> res3 = pool.submitTask(sum1, 1, 2);
    //future<int> res4 = pool.submitTask(sum1, 1, 2);
    //future<int> res5 = pool.submitTask(sum1, 1, 2);

    std::cout << res.get() << endl;
    std::cout << res1.get() << endl;
    //std::cout << res2.get() << endl;
    //std::cout << res3.get() << endl;
    //std::cout << res4.get() << endl;
    //std::cout << res5.get() << endl;
}
